package org.aperture.exploit;

import java.io.*;
//import java.util.regex.*;
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.*;
import org.eclipse.wb.swt.SWTResourceManager;

//import org.apache.commons.io.FileUtils;

public class FileTree {

	public static void getFiles(String directory, TreeItem parent) {
		File folder = new File(directory);
		File[] fileList = folder.listFiles();
		try {
			for (File file : fileList) {
	//			if(file.getName().matches(".+[.].{2,}$")) {
	////				System.out.println(file.getAbsolutePath());
	//				TreeItem item = new TreeItem(parent, SWT.NONE);
	//				item.setText(file.getName());
	//			} 
				if(file.isDirectory()) {
					TreeItem item = new TreeItem(parent, SWT.NONE);
					//item.setImage(SWTResourceManager.getImage(Main.class, "/javax/swing/plaf/metal/icons/ocean/directory.gif"));
					//item.setImage(SWTResourceManager.getImage(Main.class, "/resources/icons/crystal_clear_icons/png/32x32/filesystems/folder_blue.png"));
					//item.setImage(SWTResourceManager.getImage(Main.class, "/resources/icons/crystal_project/16x16/filesystems/folder.png"));
					//item.setImage(SWTResourceManager.getImage(Main.class, "/resources/icons/oxygen-icons-by-oxygen/png/16x16/filesystems/folder_green.png"));
					item.setImage(SWTResourceManager.getImage(Main.class, "/resources/icons/crystal_clear_icons/custom/16x16/filesystems/folder_green.png"));
					item.setText(file.getName());
					getFiles(file.getAbsolutePath(), item);
	//			} else if(file.isFile()) {
				} else if(file.isFile()) {
					TreeItem item = new TreeItem(parent, SWT.NONE);
					//item.setImage(SWTResourceManager.getImage(Main.class, "/com/sun/java/swing/plaf/windows/icons/File.gif"));
					//item.setImage(SWTResourceManager.getImage(Main.class, "/resources/icons/crystal_project/16x16/filesystems/file.png"));
					item.setImage(SWTResourceManager.getImage(Main.class, "/resources/icons/oxygen-icons-by-oxygen/png/16x16/mimetypes/application_pdf.png"));
					item.setText(file.getName());
				}
			}
		} catch (NullPointerException e) {
			
		}
		
		//System.out.println(fileList[0].getName());
		
//		for (File file : fileList) {
//			System.out.println(file.getName());
//			if(file.isFile()) {
//				TreeItem item = new TreeItem(parent, SWT.NONE);
//				item.setText(file.getName());
//				getFiles(file.getAbsolutePath(), item);
//			}
//		}
		
//	public static void main(String[] args) {
//		String parentDir = "D:/Incoming";
//		getFiles(parentDir);
//	}
	

	
	}

	public static void getDirectoryContents(String directory, TreeItem parent) {
		File folder = new File(directory);
		File[] fileList = folder.listFiles();
		try {
			for (File file : fileList) {
				if(file.isDirectory()) {
					TreeItem item = new TreeItem(parent, SWT.NONE);

					item.setImage(SWTResourceManager.getImage(Main.class, "/resources/icons/oxygen-icons-by-oxygen/png/16x16/filesystems/folder_green.png"));
					item.setText(file.getName());
		//			getFiles(file.getAbsolutePath(), item);
				} else if(file.isFile()) {
					TreeItem item = new TreeItem(parent, SWT.NONE);
					item.setImage(SWTResourceManager.getImage(Main.class, "/resources/icons/oxygen-icons-by-oxygen/png/16x16/mimetypes/application_pdf.png"));
					item.setText(file.getName());
				}
			}
		} catch (NullPointerException e) {
			
		}
	}
	
	
}
